import { doRobotList,doRobotRemove,doRobotAdd } from '@/services/robotManagement'

export default {
  namespace: 'robots',
  state: {
    data: {
      qaList: [],
      total: 0,
      suggestList: [],
    },
  },

  effects: {
    *fetchRobotList({payload,callback}, { call, put }) {
      const response = yield call(doRobotList,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *fetchRobotRemove({payload,callback}, { call, put }) {
      const response = yield call(doRobotRemove,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *fetchRobotAdd({payload,callback}, { call, put }) {
      const response = yield call(doRobotAdd,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
